home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / idlelib / ScrolledList.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  5KB  |  166 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from Tkinter import *
  5.  
  6. class ScrolledList:
  7.     default = '(None)'
  8.     
  9.     def __init__(self, master, **options):
  10.         self.master = master
  11.         self.frame = frame = Frame(master)
  12.         self.frame.pack(fill = 'both', expand = 1)
  13.         self.vbar = vbar = Scrollbar(frame, name = 'vbar')
  14.         self.vbar.pack(side = 'right', fill = 'y')
  15.         self.listbox = listbox = Listbox(frame, exportselection = 0, background = 'white')
  16.         if options:
  17.             listbox.configure(options)
  18.         
  19.         listbox.pack(expand = 1, fill = 'both')
  20.         vbar['command'] = listbox.yview
  21.         listbox['yscrollcommand'] = vbar.set
  22.         listbox.bind('<ButtonRelease-1>', self.click_event)
  23.         listbox.bind('<Double-ButtonRelease-1>', self.double_click_event)
  24.         listbox.bind('<ButtonPress-3>', self.popup_event)
  25.         listbox.bind('<Key-Up>', self.up_event)
  26.         listbox.bind('<Key-Down>', self.down_event)
  27.         self.clear()
  28.  
  29.     
  30.     def close(self):
  31.         self.frame.destroy()
  32.  
  33.     
  34.     def clear(self):
  35.         self.listbox.delete(0, 'end')
  36.         self.empty = 1
  37.         self.listbox.insert('end', self.default)
  38.  
  39.     
  40.     def append(self, item):
  41.         if self.empty:
  42.             self.listbox.delete(0, 'end')
  43.             self.empty = 0
  44.         
  45.         self.listbox.insert('end', str(item))
  46.  
  47.     
  48.     def get(self, index):
  49.         return self.listbox.get(index)
  50.  
  51.     
  52.     def click_event(self, event):
  53.         self.listbox.activate('@%d,%d' % (event.x, event.y))
  54.         index = self.listbox.index('active')
  55.         self.select(index)
  56.         self.on_select(index)
  57.         return 'break'
  58.  
  59.     
  60.     def double_click_event(self, event):
  61.         index = self.listbox.index('active')
  62.         self.select(index)
  63.         self.on_double(index)
  64.         return 'break'
  65.  
  66.     menu = None
  67.     
  68.     def popup_event(self, event):
  69.         if not self.menu:
  70.             self.make_menu()
  71.         
  72.         menu = self.menu
  73.         self.listbox.activate('@%d,%d' % (event.x, event.y))
  74.         index = self.listbox.index('active')
  75.         self.select(index)
  76.         menu.tk_popup(event.x_root, event.y_root)
  77.  
  78.     
  79.     def make_menu(self):
  80.         menu = Menu(self.listbox, tearoff = 0)
  81.         self.menu = menu
  82.         self.fill_menu()
  83.  
  84.     
  85.     def up_event(self, event):
  86.         index = self.listbox.index('active')
  87.         if self.listbox.selection_includes(index):
  88.             index = index - 1
  89.         else:
  90.             index = self.listbox.size() - 1
  91.         if index < 0:
  92.             self.listbox.bell()
  93.         else:
  94.             self.select(index)
  95.             self.on_select(index)
  96.         return 'break'
  97.  
  98.     
  99.     def down_event(self, event):
  100.         index = self.listbox.index('active')
  101.         if self.listbox.selection_includes(index):
  102.             index = index + 1
  103.         else:
  104.             index = 0
  105.         if index >= self.listbox.size():
  106.             self.listbox.bell()
  107.         else:
  108.             self.select(index)
  109.             self.on_select(index)
  110.         return 'break'
  111.  
  112.     
  113.     def select(self, index):
  114.         self.listbox.focus_set()
  115.         self.listbox.activate(index)
  116.         self.listbox.selection_clear(0, 'end')
  117.         self.listbox.selection_set(index)
  118.         self.listbox.see(index)
  119.  
  120.     
  121.     def fill_menu(self):
  122.         pass
  123.  
  124.     
  125.     def on_select(self, index):
  126.         pass
  127.  
  128.     
  129.     def on_double(self, index):
  130.         pass
  131.  
  132.  
  133.  
  134. def test():
  135.     root = Tk()
  136.     root.protocol('WM_DELETE_WINDOW', root.destroy)
  137.     
  138.     class MyScrolledList(ScrolledList):
  139.         
  140.         def fill_menu(self):
  141.             self.menu.add_command(label = 'pass')
  142.  
  143.         
  144.         def on_select(self, index):
  145.             print 'select', self.get(index)
  146.  
  147.         
  148.         def on_double(self, index):
  149.             print 'double', self.get(index)
  150.  
  151.  
  152.     s = MyScrolledList(root)
  153.     for i in range(30):
  154.         s.append('item %02d' % i)
  155.     
  156.     return root
  157.  
  158.  
  159. def main():
  160.     root = test()
  161.     root.mainloop()
  162.  
  163. if __name__ == '__main__':
  164.     main()
  165.  
  166.